package com.vip.service.shop.impl;

import com.vip.dao.shop.dao.ShopCarDao;
import com.vip.dao.shop.domain.ShopCar;
import com.vip.dao.shop.domain.ShopComm;
import com.vip.service.shop.ShopCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopCarServiceImpl implements ShopCarService {

    @Autowired
    ShopCarDao shopCarDao;


    @Override
    public ShopCar findByUserId(Long id) {
        return shopCarDao.findShopCarByUserId(id);
    }

    @Override
    public ShopCar addCarComm(Integer uid,String commName) {
        ShopCar shopCar = shopCarDao.findShopCarByUserId(uid.longValue());
        if(null != shopCar ){
            String com = shopCar.getComms();
            shopCar.setComms(com + "-" + commName);
            ShopCar shopCar1 = shopCarDao.save(shopCar);
            return shopCar1;
        }else{
            ShopCar shopCar2 = new ShopCar(uid.longValue());
            return shopCarDao.save(shopCar2);
        }

    }
}
